home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / misc / iv26_w30 / sources / banner.c next >
C/C++ Source or Header  |  1980-01-03  |  3KB  |  112 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Banner implementation.
  25.  */
  26.  
  27. #include <InterViews/banner.h>
  28. #include <InterViews/font.h>
  29. #include <InterViews/painter.h>
  30. #include <InterViews/shape.h>
  31.  
  32. static const int pad = 2*pixels;    /* space around banner text */
  33.  
  34. Banner::Banner (char* lt, char* m, char* rt) {
  35.     Init(lt, m, rt);
  36. }
  37.  
  38. Banner::Banner (const char* name, char* lt, char* m, char* rt) {
  39.     SetInstance(name);
  40.     Init(lt, m, rt);
  41. }
  42.  
  43. Banner::Banner (Painter* out, char* lt, char* m, char* rt) : (nil, out) {
  44.     Init(lt, m, rt);
  45.     Reconfig();
  46. }
  47.  
  48. void Banner::Init (char* lt, char* m, char* rt) {
  49.     SetClassName("Banner");
  50.     left = lt;
  51.     middle = m;
  52.     right = rt;
  53.     highlight = false;
  54.     inverse = nil;
  55. }
  56.  
  57. void Banner::Reconfig () {
  58.     int w;
  59.  
  60.     Font* f = output->GetFont();
  61.     lw = left == nil ? 0 : f->Width(left);
  62.     mw = middle == nil ? 0 : f->Width(middle);
  63.     rw = right == nil ? 0 : f->Width(right);
  64.     if (mw > 0) {
  65.     w = mw + 2*max(lw, rw);
  66.     } else {
  67.     w = lw + rw;
  68.     }
  69.     shape->width = 2*pad + w + f->Width("    ");
  70.     shape->height = f->Height() + 2*pad;
  71.     shape->Rigid(0, hfil, 0, 0);
  72.     Unref(inverse);
  73.     inverse = new Painter(output);
  74.     inverse->Reference();
  75.     inverse->SetColors(output->GetBgColor(), output->GetFgColor());
  76. }
  77.  
  78. Banner::~Banner () {
  79.     Unref(inverse);
  80. }
  81.  
  82. void Banner::Redraw (Coord x1, Coord y1, Coord x2, Coord y2) {
  83.     Painter* p = highlight ? inverse : output;
  84.     p->ClearRect(canvas, x1, y1, x2, y2);
  85.     if (right != nil && rx <= x2) {
  86.     p->MoveTo(rx, pad);
  87.     p->Text(canvas, right);
  88.     }
  89.     if (middle != nil && mx + mw >= x1 && mx <= x2) {
  90.     p->MoveTo(mx, pad);
  91.     p->Text(canvas, middle);
  92.     }
  93.     if (left != nil && lx + lw >= x1) {
  94.     p->MoveTo(lx, pad);
  95.     p->Text(canvas, left);
  96.     }
  97. }
  98.  
  99. void Banner::Resize () {
  100.     lx = pad;
  101.     mx = (xmax - mw) / 2;
  102.     rx = xmax - rw + 1 - pad;
  103. }
  104.  
  105. void Banner::Update () {
  106.     if (canvas != nil) {
  107.     Reconfig();
  108.     Resize();
  109.     Draw();
  110.     }
  111. }
  112.